<?php

/**
 * Created by PhpStorm.
 * User: jc234839
 * Date: 27/04/2014
 * Time: 2:52 PM
 */
class Inventory
{
    private $db;

    public function __construct(PDO $db)
    {
        $this->db = $db;
    }

    public function addInventory($productID, $colour, $size, $units)
    {
        $sql = "INSERT INTO Inventory ('ProductID', 'Colour', 'Size', 'UnitsInStock') VALUES (?, ?, ?, ?)";
        $query = $this->db->prepare($sql);

        $query->bindValue(1, $productID);
        $query->bindValue(2, $colour);
        $query->bindValue(3, $size);
        $query->bindValue(4, $units);

        try {
            $query->execute();

            if ($query) return "Inventory was successfully added to the database!";

        } catch (PDOException $e) {
            echo $e->getMessage();
        }
        return "Inventory was NOT successfully added to the database!";
    }

    public function updateInventory($inventoryID, $colour, $size, $unitsInStock)
    {
        $sql = "UPDATE Inventory SET Colour = ?, Size = ?, UnitsInStock = ? WHERE InventoryID = ?";
        $query = $this->db->prepare($sql);

        $query->bindValue(1, $colour);
        $query->bindValue(2, $size);
        $query->bindValue(3, $unitsInStock);
        $query->bindValue(4, $inventoryID);

        try {
            return $query->execute();

        } catch (PDOException $e) {
            echo $e->getMessage();
        }
        return false;
    }

    public function deleteInventory($inventoryID)
    {
        $sql = "DELETE FROM Inventory WHERE InventoryID = ?";
        $query = $this->db->prepare($sql);

        $query->bindValue(1, $inventoryID);

        try {
            $query->execute();
            if ($query) return "Inventory was successfully removed!";

        } catch (PDOException $e) {
            echo $e->getMessage();
        }
        return "Unable to remove Inventory!";
    }
} 